//
//  ConnectOnViewController.m
//  Light
//
//  Created by 骁唐 on 15/9/22.
//  Copyright (c) 2015年 骁唐. All rights reserved.
//

#import "ConnectOnViewController.h"
#import "HomeTwoViewController.h"
#import "SliderViewController.h"
#import "constantDefinition.h"
#import "SetViewController.h"
#import "AppDelegate.h"
#import "UserConfig.h"
@interface ConnectOnViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *backGround;

@end

@implementation ConnectOnViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //设置蓝牙为已经连接状态
    AppDelegate *delegate = [[UIApplication sharedApplication]delegate];
    delegate.Bluetooth = YES;//蓝牙连接
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -
#pragma mark 配对成功，完成，点击界面跳转
- (IBAction)CompleteClick
{
    AppDelegate *delegate = [[UIApplication sharedApplication]delegate];
    delegate.Bluetooth = YES;//蓝牙连接
    UserConfig *config = [UserConfig sharingUserConfig];
    [config setConnectCool:@"1"];//绑定
    if (self.mark || [delegate.markGo isEqualToString:@"setting"])
    {//如果是设置进入的
        NSLog(@"%d",self.mark);
        if (delegate.markIsgetHardNumberHome)
        {//如果首页检查 有更新版本，直接跳转到RootView，然后显示主界面。
            delegate.markIsgetHardNumberHome = NO;//清零
            delegate.isUpdateHardWare = YES;//标记现在在进行眼罩升级
            [self.navigationController popToRootViewControllerAnimated:YES];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"checkUpdateConnect" object:nil];//发送通知 进入主界面，进行判断是否升级的。
        }
        else
        {//如果首页检查 没有反馈版本更新
            for (UIViewController *controller in self.navigationController.viewControllers) {
                if ([controller isKindOfClass:[SetViewController class]]) {
                    delegate.isUpdateHardWare = NO;//标记现在在进行眼罩升级
                    [self.navigationController popToViewController:controller animated:YES];
                }
            }
        }
    }
    else
    {//注册进入的
        TJJLog(@"注册进入的绑定成功界面");
        BOOL HaveRoot = NO;//标记是否有Root
        for (UIViewController * controller in self.navigationController.viewControllers)
        {
            if ([controller isKindOfClass:[SliderViewController class]])
            {//如果是rootView
                HaveRoot = YES;
                TJJLog(@"有Root");
                delegate.isUpdateHardWare = NO;//标记现在在进行眼罩升级
                [self.navigationController popToViewController:controller animated:YES];
            }
        }
        if (!HaveRoot)
        {
            TJJLog(@"重新创建Root");
            HomeTwoViewController *homet = [[HomeTwoViewController alloc] init];
            //SXW__标记，用的SliderViewController框架。
            SliderViewController *slider = [SliderViewController sharedSliderController];
            slider.MainVC = homet;
            UIStoryboard *userSt = [UIStoryboard storyboardWithName:@"User" bundle:nil];
            slider.LeftVC = [userSt instantiateViewControllerWithIdentifier:@"userViewId"];
            if (SCREEN_WIDTH > 320)
            {//如果是6以上的手机
                slider.LeftSContentOffset =  SCREEN_WIDTH-WIDTH_MAIN_6*SCREEN_SCALE;//SXW__设置侧边栏
            }
            else
            {//如果是6以下的手机
                slider.LeftSContentOffset =  SCREEN_WIDTH-WIDTH_MAIN*SCREEN_SCALE;//SXW__设置侧边栏
            }        slider.LeftSContentScale = 1;//左视图缩小，1表示不缩小。
            UINavigationController *navigationVc = [[UINavigationController alloc]initWithRootViewController:slider];
            navigationVc.navigationBar.hidden = YES;
            delegate.window.rootViewController = navigationVc;
        }
    }
}

#pragma mark -
#pragma mark viewWillAppear
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //强制竖屏
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:
                                        UIInterfaceOrientationPortrait]  forKey:@"orientation"];
    long long int currentTimeInt = [TJJDefines getTimeIntSince1970Current];
    if (currentTimeInt>=16200&& currentTimeInt <=34200) {
        self.backGround.image = [UIImage imageNamed:@"backgroundOne"];
    }else if (currentTimeInt>34200 && currentTimeInt<=55800)
    {
        self.backGround.image = [UIImage imageNamed:@"backgroundTwo"];
    }else if (currentTimeInt>55800 && currentTimeInt<=70200)
    {
        self.backGround.image = [UIImage imageNamed:@"backgroundThree"];
    }else if(currentTimeInt >70200 || currentTimeInt<16200)
    {
        self.backGround.image = [UIImage imageNamed:@"background_night"];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
